import Vue from 'vue'
import Router from 'vue-router'
import Movie from './views/movie/movie.vue'
import Cinema from './views/cinema/cinema.vue'
import News from './views/news.vue'
import Myself from './views/myself/myself.vue'
import Nowplaying from './views/movie/nowplaying.vue'
import Willplay from './views/movie/willplay.vue'
import movieDetail from './views/movie/movieDetail.vue'
import CinemaDetail from './views/cinema/CinemaDetail.vue'
import Cmoviedetail from './views/cinema/Cmoviedetail'
import Playdetail from './views/cinema/playdetail.vue'
import Location from './views/location/location.vue'
import Login from './views/login/login.vue'
import Purchase from './views/purchase/purchase.vue'
import Choosecinemas from './views/movie/choosecinemas.vue'
import User from './views/myself/user.vue'
import Settings from './views/myself/settings.vue'
import store from '@/store.js'

Vue.use(Router)

var router= new Router({
  routes: [
    {
      path: '/',
      component: Movie,
      children:[{
        path:'',
        redirect:'/movie/nowplaying'
      }]

    },
    {
      path: '/movie',
      component: Movie,
      children:[{
        path:'',
        redirect:'/movie/nowplaying'
      },{
        path:'nowplaying',
        component:Nowplaying,
        meta:{
          hasFoot:true
        }
      },
      {
        path:'willplay',
        component:Willplay,
        meta:{
          hasFoot:true
        }

      }
    ]
    },
    {
      path:'/movie/:id',
      component:movieDetail

    },
    {
      path:'/movie/:id/cinemas',
      component:Choosecinemas

    },
    {
      path:'/cinema',
      component:Cinema,
      meta:{
        hasFoot:true
      }

    },
    {
      path:'/cinemas/:id',
      component:CinemaDetail,
      name:'CinemaDetail',
      children:[{
        path:'films/:mid',
        component:Cmoviedetail,
        name:'Cmoviedetail',
        children:[{
          path:':date',
          component:Playdetail,
          name:'playdetail'
        }]
      }]
    },
    {
      path:'/news',
    component:News
  },
  {
    path:'/myself',
    component:Myself,
    meta:{
      hasFoot:true
    }

  },
  {
    path:'/location',
    component:Location
  },
  {
    path:'/login',
    component:Login
  },
  {path:'/purchase/cinemas/:id/films/:mid/:date',
  component:Purchase
   },
   {path:'/user',
   component:User
    },
    {path:'/settings',
    component:Settings
     }
 
 
  ]
})

var whiteList=['/location','myself']
router.beforeEach((to,from,next)=>{
  if(whiteList.indexOf(to.path)==-1&&!store.state.cityId){
    next('/location')
  }

  if(to.path.indexOf('purchase')!==-1&&!store.state.status){
         next('/login')
  }

  next()

})

export default router
